<?php

namespace App\Http\Controllers\Api;

use App\Goods;
use App\Http\Controllers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Order;
use Illuminate\Http\Request;

class GoodsController extends Controller
{
    use ApiResponse;

    //0 正常商品  1虚拟商品
    public $type;
    public function __construct()
    {
        $this->type=\request('type',0);
    }
    public function index(Request $request)
    {
       $list=Goods::whereType($this->type)->where('status',1)->orderByDesc("sort")->paginate($request->get('size',10));
       return $this->data($list);
    }
    public function show($id)
    {
        $info=Goods::with(['skus'])->where('status',1)->where('id',$id)->first();
        if (!$info){
            return $this->message_error("商品已下架");
        }
        return $this->data($info);
    }
}
